package net.yeah.mickey_zhouyou.database.util;

import java.util.HashMap;
import java.util.Map;

import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToBool;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToBooleanClass;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToByte;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToByteClass;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToChar;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToCharacterClass;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToDate;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToDouble;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToDoubleClass;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToFloat;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToFloatClass;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToInt;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToIntegerClass;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToLong;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToLongClass;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToShort;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToShortClass;
import net.yeah.mickey_zhouyou.database.util.string_policy.ConvertToString;
import net.yeah.mickey_zhouyou.database.util.string_policy.DateToStringPolicy;
import net.yeah.mickey_zhouyou.database.util.string_policy.DefaultToStringPolicy;
import net.yeah.mickey_zhouyou.database.util.string_policy.IStringToObjectPolicy;
import net.yeah.mickey_zhouyou.database.util.string_policy.IObjectToStringPolicy;

public class ObjectStringConvertPolicyUtil {

	private static final Map<String, IObjectToStringPolicy> toStringPolicyMap = new HashMap<String, IObjectToStringPolicy>();

	private static final Map<String, IStringToObjectPolicy<?>> toObjectPolicyMap = new HashMap<String, IStringToObjectPolicy<?>>();

	static {
		DefaultToStringPolicy defaultPolicy = new DefaultToStringPolicy();

		toStringPolicyMap.put(boolean.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(boolean.class.getName(), new ConvertToBool());

		toStringPolicyMap.put(char.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(char.class.getName(), new ConvertToChar());

		toStringPolicyMap.put(byte.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(byte.class.getName(), new ConvertToByte());

		toStringPolicyMap.put(short.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(short.class.getName(), new ConvertToShort());

		toStringPolicyMap.put(int.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(int.class.getName(), new ConvertToInt());

		toStringPolicyMap.put(long.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(long.class.getName(), new ConvertToLong());

		toStringPolicyMap.put(float.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(float.class.getName(), new ConvertToFloat());

		toStringPolicyMap.put(double.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(double.class.getName(), new ConvertToDouble());

		toStringPolicyMap.put(Boolean.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(Boolean.class.getName(),
				new ConvertToBooleanClass());

		toStringPolicyMap.put(Character.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(Character.class.getName(),
				new ConvertToCharacterClass());

		toStringPolicyMap.put(Byte.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(Byte.class.getName(), new ConvertToByteClass());

		toStringPolicyMap.put(Short.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(Short.class.getName(), new ConvertToShortClass());

		toStringPolicyMap.put(Integer.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(Integer.class.getName(),
				new ConvertToIntegerClass());

		toStringPolicyMap.put(Long.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(Long.class.getName(), new ConvertToLongClass());

		toStringPolicyMap.put(Float.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(Float.class.getName(), new ConvertToFloatClass());

		toStringPolicyMap.put(Double.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(Double.class.getName(),
				new ConvertToDoubleClass());

		toStringPolicyMap.put(String.class.getName(), defaultPolicy);
		toObjectPolicyMap.put(String.class.getName(), new ConvertToString());

		toStringPolicyMap.put(java.util.Date.class.getName(),
				new DateToStringPolicy());
		toObjectPolicyMap.put(java.util.Date.class.getName(),
				new ConvertToDate());

	}

	static public IStringToObjectPolicy<?> getToObjectPolicy(String className) {
		return toObjectPolicyMap.get(className);
	}

	static public IObjectToStringPolicy getToStringPolicy(String className) {
		return toStringPolicyMap.get(className);
	}
}
